#define DEBUG
#include <cstdio>
#define MAXN 100000
#define MAXM 1000000

using namespace std;

int min(int a, int b) {
  return a<b ? a : b;
}

int max(int a, int b) {
  return a>b ? a : b;
}

void sort(int *a, int l, int r) {
  int i=l, j=r, mid=a[(l+r)/2], temp;
  for (; i<=j; ) {
    for (; a[j]<mid; j--);
    for (; a[i]>mid; i++);
    if (i<=j) {
      temp=a[i], a[i]=a[j], a[j]=temp;
      i++, j--;
    }
  }
  if (i<r) {
    sort(a, i, r);
  }
  if (j>l) {
    sort(a, l, j);
  }
}

void initSet(int *set, int n) {
  for (int i=1; i<=n; i++) {
    set[i]=i;
  }
}

int getFa(int *set, int o) {
  if (set[o]!=o) {
    set[o] = getFa(set, set[o]);
  }
  return set[o];
}

bool isConnected(int *set, int u, int v) {
  return getFa(set, u)==getFa(set, v);
}

void merge(int *set, int u, int v) {
  if (!isConnected(set, u, v)) {
    set[getFa(set, u)] = getFa(set, v);
  }
}

class Graph {
public:
  int n, m, ind[MAXN+1], tail[MAXN+1], v[MAXN+1], to[MAXM+1], link[MAXM+1], set[MAXN+1], dfn[MAXN+1], low[MAXN+1], code[MAXN+1];
  bool mark[MAXN+1];

  void init(int n) {
    this->n = n, m=0;
    initSet(set, n);
  }

  void addSide(int u, int v) {
    merge(set, u, v);
    m++;
    to[m]=v;
    link[m]=ind[u];
    ind[u] = m;
    if (!tail[u]) {
      tail[u] = m;
    }
  }

  void makeDfn(int o) {
    static bool book[MAXN+1];
    static int stack[MAXN+1];
    book[o] = true;
    stack[++stack[0]] = o;
    low[o]=dfn[o]=++dfn[0];
    for (int i=ind[o]; i; i=link[i]) {
      if (!book[to[i]]) {
	makeDfn(to[i]);
      }
      low[o] = min(low[o], low[to[i]]);
    }
    
    if (low[o]==dfn[o]) {
      for (; stack[stack[0]]!=o; stack[0]--) {
	link[tail[o]] = ind[stack[stack[0]]];
	tail[o] = tail[stack[stack[0]]];
	code[stack[stack[0]]] = o;
	v[o] += v[stack[stack[0]]];
      }
      stack[0]--;
      code[o] = o;
      for (int i=ind[o]; i; i=link[i]) {
	if (code[to[i]]==o) {
	  mark[i] = true;
	}
      }
    }
  }

  void build() {
    for (int i=1; i<=n; i++) {
      if (!code[i]) {
	makeDfn(i);
      }
    }
  }

  int solve(int o) {
    static int ans[MAXN+1]; // city
    if (!ans[o]) {
      ans[o] = v[o];
      for (int i=ind[o]; i; i=link[i]) {
	if (!mark[i]) {
	  ans[o] = max(ans[o], v[o]+solve(code[to[i]]));
	}
      }
    }
    return ans[o];
  }

  int getKthValueSum(int k) {
    static int ans[MAXN+1]; // island
    for (int i=1; i<=n; i++) {
      ans[getFa(set, i)] = max(ans[getFa(set, i)], solve(i));
    }

    sort(ans, 1, n);
    int sum=0;
    for (int i=1; i<=k+1 && i<=n; i++) {
      sum += ans[i];
    }
    return sum;
  }
};

int main() {
  freopen("azeroth.in", "r", stdin);
  freopen("azeroth.out", "w", stdout);

  static Graph g;
  int n, m;
  scanf("%d %d", &n, &m);
  g.init(n);
  for (int i=1; i<=m; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    g.addSide(u, v);
  }
  for (int i=1; i<=n; i++) {
    scanf("%d", g.v+i);
  }
  int k;
  scanf("%d", &k);
  g.build();

  printf("%d\n", g.getKthValueSum(k));

  fcloseall();
  return 0;
}
